package com.orderserver.controller;


import com.orderserver.constants.RabbitmqConstant;
import com.orderserver.model.OrderInfo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;

@RequestMapping("/orderServer")
@RestController
public class OrderServer {
    @Autowired
    RabbitTemplate rabbitTemplate;

   @RequestMapping("/order")
    public String order(){
       String orderId= UUID.randomUUID().toString();
       rabbitTemplate.convertAndSend("", RabbitmqConstant.ORDER_QUEUE,"发送订单单号为："+orderId);
       return "发送订单成功";
   }

   @RequestMapping("/order1")
    public String order1(){
       OrderInfo orderInfo=new OrderInfo();
       orderInfo.setOrderId(UUID.randomUUID().toString());
       orderInfo.setOrderName("商品"+new Random().nextInt(100));
       rabbitTemplate.convertAndSend("", RabbitmqConstant.ORDER_QUEUE, orderInfo);
       return "发送订单成功";
   }

}
